[極短篇] XMLHttpRequest


Posted by Lauviah0622 on 2020-08-03

最基本要有兩個東西

  • XMLHttpRequest.open() 初始化整個 XMLHttpRequest ,設定 request 類型(GET 甚麼的)、URL、還有要不要非同步(到底甚麼 Case 會不用...)
  • XMLHttpRequest.send() 這個一定一定要放在最後,設定好在 send tree pay

通常會加上這些

  • XMLHttpRequest.onload = callback
  • XMLHttpRequest.onerror = callback
    上面這兩個相當於
    XMLHttpRequest.addEventListener('load', callback)
    XMLHttpRequest.addEventListener('error', callback)
    

可以用

  • XMLHttpRequest.response 拿 Request 的 body,可能有各種形式
  • XMLHttpRequest.status 拿 HTTP status

那要怎麼拿 Header 阿... => XMLHttpRequest.getResponseHeader()
XMLHttpRequest.setRequestHeader() 要記得放在 send() 之前。

Big guy is John,感謝收看。

參考:MDN


#XMLHttpReqeust







Related Posts

[ 前端工具 ] - gulp, Babel, SCSS, uglyfy

[ 前端工具 ] - gulp, Babel, SCSS, uglyfy

[ Day 03 ] 用 Puppeteer 來做自動化機器人吧 (二) : 基礎篇

[ Day 03 ] 用 Puppeteer 來做自動化機器人吧 (二) : 基礎篇

Day07 從 React-router 看 History API

Day07 從 React-router 看 History API


Comments